package com.example.wechattakeaway.controller;

import com.example.wechattakeaway.entity.SysUser;
import com.example.wechattakeaway.form.userform.ChangePwdForm;
import com.example.wechattakeaway.form.userform.InsertUserForm;
import com.example.wechattakeaway.form.userform.LoginForm;
import com.example.wechattakeaway.form.userform.UpdateUserForm;
import com.example.wechattakeaway.service.UserService;
import com.example.wechattakeaway.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(value = "用户管理界面",tags = {"用户个人信息管理"})
@RestController
@RequestMapping("/SysUserController")
public class SysUserController {

    @Autowired
    UserService userService;

    @ApiOperation(value = "用户注册",notes = "微信端")
    @PostMapping("/UserRegister")
    public ResultVO UserRegister(@Validated InsertUserForm insertUserForm){
        return userService.UserRegister(insertUserForm);
    }

    @ApiOperation(value = "根据用户name更新用户信息",notes = "微信端")
    @PostMapping("/UpdateUser")
    public ResultVO UpdateUser(UpdateUserForm updateUserForm){
        return userService.UpdateUser(updateUserForm);
    }

    @ApiOperation(value = "更新用户密码",notes = "微信端")
    @PostMapping("/UserChangerPwd")
    public ResultVO UserChangePwd(ChangePwdForm changePwdForm){
        return userService.UserChangerPwd(changePwdForm);
    }

    @ApiOperation(value = "更新用户角色",notes = "不考虑，仅有系统管理员有权限")
    @PostMapping("/UpdateUserRole")
    public ResultVO UpdateUserRole(Integer userRole,Integer sysuserId){
        return userService.UpdateUserRole(userRole, sysuserId);
    }

    @ApiOperation(value = "用户尝试登陆",notes = "微信端or网页端")
    @PostMapping("/UserLogin")
    public ResultVO UserLogin(LoginForm loginForm){
        return userService.UserLogin(loginForm);
    }

    @ApiOperation(value = "测试获取在线登录用户",notes = "暂不考虑，微信端or网页端")
    @PostMapping("/getCurrentUser")
    public SysUser getCurrentUser(){
        return userService.getCurrentUser();
    }

    @ApiOperation(value = "用户退出登录",notes = "暂不考虑，微信端or网页端")
    @PostMapping("/UserLoginOut")
    public ResultVO UserLoginOut(){
        return userService.UserLoginOut();
    }

    @ApiOperation(value = "根据用户id查询用户",notes = "暂不考虑，都可以用")
    @PostMapping("/SelectUserById")
    public ResultVO SelectUserById(Integer sysuserId){
        return userService.SelectUserById(sysuserId);
    }

    @ApiOperation(value = "测试查询所有的用户",notes = "暂不考虑，仅系统管理员有权限")
    @PostMapping("/SelectAllUser")
    public ResultVO SelectAllUser(Integer pageNum){
        return userService.SelectAllUser(pageNum);
    }

    @ApiOperation(value = "根据用户name删除一个用户",notes = "暂不考虑，仅系统管理员有权限")
    @PostMapping("/DeleteUserByName")
    public ResultVO DeleteUserById(String sysuserName){
        return userService.DeleteUserById(sysuserName);
    }

    @ApiOperation(value = "输入手机号，获取手机验证码",notes = "网页端")
    @PostMapping("/GetPhoneCode")
    public ResultVO GetPhoneCode(String userPhone){
        return userService.GetPhoneCode(userPhone);
    }

    @ApiOperation(value = "根据用户输入验证码校验，成功即可登录",notes = "这是商家web端接口")
    @PostMapping("/CheckPhoneCode")
    public ResultVO CheckPhoneCode(String userPhone,String code){
        return userService.CheckPhoneCode(userPhone, code);
    }

    @ApiOperation(value = "根据用户名查询用户",notes = "根据用户名（这里是微信名）查询")
    @PostMapping("/SelectUserByName")
    public ResultVO SelectUserByName(String userName){
        return userService.SelectUserByName(userName);
    }

}
